package com.tianyuan.lims.common.config.druid;

import com.aliyuncs.utils.StringUtils;
import com.jfinal.plugin.druid.IDruidStatViewAuth;
import com.tianyuan.lims.utils.BaseUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhangzhiwei
 * 配置druid的进入规则，暂定为只要登录就可查看
 */
public class DruidConfig implements IDruidStatViewAuth {
    @Override
    public boolean isPermitted(HttpServletRequest request) {
        String token = BaseUtil.getToken(request);
        //return RedisManager.getRedis().exists(token);
        Object sessionToken = request.getSession().getAttribute("token");
        sessionToken = sessionToken == null ? "" : sessionToken;
        if (StringUtils.isEmpty(token) && StringUtils.isNotEmpty(sessionToken.toString())) {
            return true;
        }
        return false;
    }
}
